<?php
	require '../class/autoload.php';

	// 10003 预留给变量检测异常的返回结果	_checkVal($name,,,);


	$tmp_arr = array();		//返回数据集合

	$type = $_POST['type'];

	//检测用户名
	$user = I('user');
	if(!$user){
		$tmp_arr['stat'] = '10001';
		exit(json_encode($tmp_arr));
	}
	
	//验证token
	$token_arr = array(		//跳过的项
		'login',
	);
	if(!in_array($_REQUEST['type'],$token_arr)){
		$token1 = I('token1');
		if(!VerifyToken($user,$token1)){
			$tmp_arr['stat'] = '10002';
			//exit(json_encode($tmp_arr));	//token验证失败
		}
	}


	//获取token
	$tokenv_arr = array(		//跳过获取token的项
		// 'AdminExit',
	);
	if(!in_array($_REQUEST['type'],$tokenv_arr)){
		$tmp_arr['token1'] = SetToken($user);
	}




	switch($type){



		//删除征候下的症状
		case 'delZhengHouSubZhengZhuang':
			$id = intval(I('id'));
			$hid = intval(I('hid'));
			_checkVal($id,$hid);
			$zheng_hou = new zheng_hou();
			$res = $zheng_hou->_delZhengHouSubZhengZhuang($id,$hid);
			if($res){
				$tmp_arr['stat'] = 'ok';
				_deleteZhengHouCache();
			}else{
				$tmp_arr['stat'] = 'err';
			}
		break;



		//给征候添加症状
		case 'zhengHouAddZhengZhuang':
			$id = I('id');
			$list = I('list');
			_checkVal($id,$list);
			$zheng_hou = new zheng_hou();
			$res = $zheng_hou->_zhengHouAddZhengZhuang($id,$list);
			if($res){
				$tmp_arr['stat'] = 'ok';
				_deleteZhengHouCache();
			}else{
				$tmp_arr['stat'] = 'err';
			}
		break;



		//征候删除
		case 'zhengHouDel':
			$id = intval(I('id'));
			_checkVal($id);
			$zheng_hou = new zheng_hou();
			$res = $zheng_hou->_zhengHouDel($id);
			if($res){
				$tmp_arr['stat'] = 'ok';
				_deleteZhengHouCache();
			}else{
				$tmp_arr['stat'] = 'err';
			}
		break;



		//征候重命名
		case 'zhengHouRname':
			$id = intval(I('id'));
			$name = I('name');
			_checkVal($id,$name);
			$zheng_hou = new zheng_hou();
			$res = $zheng_hou->_zhengHouRname($id,$name);
			if($res){
				$tmp_arr['stat'] = 'ok';
				_deleteZhengHouCache();
			}else{
				$tmp_arr['stat'] = 'err';
			}
		break;




		//征候上移下移
		case 'zhengHou_upDown':
			$ctype = I('ctype');
			$id = intval(I('id'));
			_checkVal($id,$ctype);
			$zheng_hou = new zheng_hou();
			$res = $zheng_hou->_zhengHou_upDown($id,$ctype);
			if($res){
				$tmp_arr['stat'] = 'ok';
			}else{
				$tmp_arr['stat'] = 'err';
			}
		break;


		//获取征候列表
		case 'getZhengHouList':
			$ctype = intval(I('ctype'));
			_checkVal($ctype);
			$tmp_arr = _getZhengHouList($tmp_arr,$ctype);	//获取征候列表 function.php
		break;



		//添加征候
		case 'addZhengHou':
			$name = I('name');
			$ctype = intval(I('ctype'));
			_checkVal($name,$ctype);
			$zheng_hou = new zheng_hou();
			$res = $zheng_hou->_addZhengHou($name,$ctype);
			if($res){
				$tmp_arr['stat'] = 'ok';
				_deleteZhengHouCache();
			}else{
				$tmp_arr['stat'] = 'err';
			}
		break;



		//删除症状
		case 'delSubItem':
			$id = intval(I('id'));
			_checkVal($id);
			$zheng_zhuang = new zheng_zhuang();
			$res = $zheng_zhuang->_delSubItem($id);
			if($res){
				$tmp_arr['stat'] = 'ok';
				_deleteZhengZhuangCache();
			}else{
				$tmp_arr['stat'] = 'err';
			}
		break;

		//症状排序的上下移动
		case 'itemUpDown':
			$id = intval(I('id'));
			$ctype = I('ctype');
			_checkVal($id,$id);
			$zheng_zhuang = new zheng_zhuang();
			$res = $zheng_zhuang->_itemUpDown($id,$ctype);
			if($res){
				$tmp_arr['stat'] = 'ok';
				_deleteZhengZhuangCache();
			}else{
				$tmp_arr['stat'] = 'err';
			}
		break;



		//症状分类名重命名
		case 'classRname':
			$id = intval(I('id'));
			$name = I('name');
			_checkVal($id,$name);
			$zheng_zhuang = new zheng_zhuang();
			$res = $zheng_zhuang->_classRname($id,$name);
			if($res){
				$tmp_arr['stat'] = 'ok';
				_deleteZhengZhuangCache();
			}else{
				$tmp_arr['stat'] = 'err';
			}
		break;




		//添加症状
		case 'addClassItem':
			$name = I('name');
			$classId = intval(I('classId'));
			_checkVal($name,$classId);
			$zheng_zhuang = new zheng_zhuang();
			$res = $zheng_zhuang->_addClassItem($classId,$name);
			if($res){
				$tmp_arr['stat'] = 'ok';
				//删除症状列表的文件缓存
				_deleteZhengZhuangCache();
			}else{
				$tmp_arr['stat'] = 'err';
			}
		break;



		//获取症状信息集合并分类排序
		case 'getClassList':
			$tmp_arr = _getClassList($tmp_arr);
		break;



		//添加症状分类
		case 'addClass':
			$typeName = I('typeName');
			_checkVal($typeName);
			$zheng_zhuang = new zheng_zhuang();
			if($zheng_zhuang->_addClass($typeName)){
				$tmp_arr['stat'] = 'ok';
				//删除症状列表的文件缓存
				_deleteZhengZhuangCache();
			}else{
				$tmp_arr['stat'] = 'err';
			}
		break;


		case 'login':
			$pwd = I('pwd');
			_checkVal($pwd);
			if($user == 'a' && $pwd == 'a'){
				$tmp_arr['stat'] = 'ok';
			}else{
				$tmp_arr['stat'] = 'err';
			}
		break;

		default:
			exit('default');


	}
	exit(json_encode($tmp_arr));